<?php 

if (isset($_GET['id'])) {
  $id = $_GET['id'];
  $user = $_SESSION['user'];
  $sql = 'select user_name from messages where id=?';
  $username = query($sql,[$id])[0];
  if (count($username)>0 && $username['user_name']==$user['user_name']){
    $sql = 'delete from messages where id=?';
    execute($sql,[$id]);
  }
}

header('Location:'. url('index'));